extends PanelContainer

const ICON = preload("res://icon.svg")

@onready var texture_rect: TextureRect = $MarginContainer/TextureRect
@onready var quantity_label: Label = $QuantityLabel

signal slot_clicked(index: int, buton_index: int)

func set_slot_data(slot_data: SlotData) -> void:
	if not slot_data:
		return
	var item_data = slot_data.item_data
	texture_rect.texture = item_data.texture
	if not item_data.texture:
		texture_rect.texture = ICON
	
	if slot_data.quantity > 1:
		quantity_label.text = "x%s" % slot_data.quantity
		quantity_label.show()
	else:
		quantity_label.hide()

func _on_gui_input(event: InputEvent) -> void:
	if event is InputEventMouseButton \
		and event.is_pressed() \
		and (
			event.button_index == MOUSE_BUTTON_LEFT 
			or event.button_index == MOUSE_BUTTON_RIGHT
			) :
		slot_clicked.emit(get_index(), event.button_index)
